#include "common.h"

common::common(QObject *parent) : QObject(parent)
{

}
INT16S  common::Hex2Binary(INT8U * hex,INT16U len, INT8U * buffer)
{
       INT16U i;

       char ch;
       if(hex==NULL) return 0;

       for(i=0;i<len;i+=2)
       {
           ch=hex[i];
           *buffer = 0;
           if(ch >='0' && ch <='9') *buffer += ch-'0';
           else if(ch >='a' && ch <='f')  *buffer += ch-'a'+10;
           else if(ch >='A' && ch <='F')  *buffer += ch-'A'+10;
           else  return -1;  // 错误的HEX
           *buffer *= 16;

           ch=hex[i+1];
           if(ch >='0' && ch <='9') *buffer += ch-'0';
           else if(ch >='a' && ch <='f')  *buffer += ch-'a'+10;
           else if(ch >='A' && ch <='F')  *buffer += ch-'A'+10;
           else  return -1;  // 错误的HEX
           buffer++;
       }
       return len/2;
}
